package org.example;

import java.util.ArrayList;
import java.util.List;

public class Test4 {
    //;eetcode 46 全排列 https://leetcode.cn/problems/permutations/description/
    public List<List<Integer>> ret;
    public List<Integer> path;
    public int[] hash;
    public List<List<Integer>> permute(int[] nums) {
        ret = new ArrayList<>();
        path = new ArrayList<>();
        hash = new int[21];
        backtracking(nums);
        return ret;
    }

    public void backtracking(int[] nums) {
        if (path.size() == nums.length) {
            ret.add(new ArrayList<>(path));
        }
        for (int i = 0; i < nums.length; i++) {
            if (hash[nums[i] + 10] == 0) {
                path.add(nums[i]);
                hash[nums[i] + 10] = 1;
                backtracking(nums);
                path.remove(path.size() - 1);
                hash[nums[i] + 10] = 0;
            }
        }
    }

    public static void main(String[] args) {
        Test4 test4 = new Test4();
        int[] arr = {0,1};
        test4.permute(arr);
        System.out.println(555);
    }
}
